import request from '@/utils/request'
import store from '@/store'
//const ascriptionId = store.state.userInfo.ascriptionId;
// 通知公告

// 页面内容 左侧树 通知分类
export function getPage(queryParams) {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
    currentPage: queryParams.currentPage,
    pagesize: queryParams.pagesize
  }
  return request({
    url: '/getNoticePage',
    method: 'post',
    data: data
  })
}

// 数据列表
export function listData(queryParams) {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
    currentPage: queryParams.currentPage,
    pagesize: queryParams.pagesize,
    keywords: queryParams.keywords,
    category: queryParams.category, //通知分类id
    startTime: queryParams.startTime, //发布时间 开始时间
    endTime: queryParams.endTime, //发布时间 结束时间
  }
  return request({
    url: '/getNoticeList',
    method: 'post',
    data: data
  })
}

// 新增
export function addData(val) {
  const data = {
    projectContent: {
      ascriptionId: store.state.userInfo.ascriptionId, //机构 id
      categoryId: val.categoryId, //通知分类id
      category: val.category, //通知分类
      title: val.title, //标题
      content: val.content, //内容
      thePic: val.thePic, //相关配图
      topping: val.topping, //是否置顶 0-不置顶 1-置顶
      reviewerLevel: val.reviewerLevel, //发布级别 0-部门发布 1-人员发布
      departmentId: val.departmentId, //发布部门 id
      department: val.department, //发布部门
      reviewerId: val.reviewerId, //发布人id
      reviewer: val.reviewer, //发布人
      reviewTime: val.reviewTime, //发布时间
      theLink: val.theLink, //附件
      sort: val.sort //位置排序
    }
  }
  return request({
    url: '/addNotice',
    method: 'post',
    data: data
  })
}

// 获取单条数据
export function getData(theid) {
  const data = {
    theid
  }
  return request({
    url: '/getNoticeData',
    method: 'post',
    data: data
  })
}

// 修改
export function updateData(val) {
  const data = {
    projectContent: {
      theid: val.theid, //id
      categoryId: val.categoryId, //通知分类id
      category: val.category, //通知分类
      title: val.title, //标题
      content: val.content, //内容
      thePic: val.thePic, //相关配图
      topping: val.topping, //是否置顶 0-不置顶 1-置顶
      reviewerLevel: val.reviewerLevel, //发布级别 0-部门发布 1-人员发布
      departmentId: val.departmentId, //发布部门 id
      department: val.department, //发布部门
      reviewerId: val.reviewerId, //发布人id
      reviewer: val.reviewer, //发布人
      reviewTime: val.reviewTime, //发布时间
      theLink: val.theLink, //附件
      sort: val.sort //位置排序
    }
  }
  return request({
    url: '/updateNotice',
    method: 'post',
    data: data
  })
}

// 删除
export function delData(theid) {
  const data = {
    theid
  }
  return request({
    url: '/delNotice',
    method: 'post',
    data: data
  })
}

// 批量删除   idListStr id列表  逗号隔开
export function delMultiData(idListStr) {
  const data = {
    idListStr
  }
  return request({
    url: '/delMultipleNotice',
    method: 'post',
    data: data
  })
}

// 状态
export function changeEnable(theid, hot) {
  const data = {
    projectContent: {
      theid,
      hot
    }
  }
  return request({
    url: '/changeHotNotice',
    method: 'post',
    data: data
  })
}